const app = getApp()
const cookieUtil = require("../../utils/manager_cookie.js")
Page({
	data: {
		marqueeProps: {
			loop: true,
			leading: 0,
			trailing: 800,
			fps: 40,
		},
		closeShow: true,
		noticeType: 'normal',
		managerClubs:[],
		arrIndex: 0,
	},
	onLoad() {
		
		const url = app.globalData.baseUrl + app.globalData.organizerClubUrl
		const cookie = cookieUtil.getCookieFromStorage().data
		let headers = {
			cookie
		}

		//从服务起获得数据
		let promise = new Promise((resolve, reject) => {

			let headers = {}
			headers.cookie = cookie

			my.request({
				url,
				method: "GET",
				headers,
				success: (res) => {
					resolve(res)
				}
			})
		})

		promise.then((res) => {
			console.log(res)
			//如果未登录则进行跳转
			if (res.data.code == "fail") {
				cookieUtil.setCookieToStorage("")
				app.globalData.managerStatus = false
				my.redirectTo({
					url: "/pages/manager_login/manager_login"
				})
			}
			let managerClubs = res.data.data
			this.setData({
				managerClubs
			})
			
		})
	},
	toParticipant(e) {
		console.log(e);
		const clubId = e.currentTarget.dataset.clubId
		my.navigateTo({
			url: "../../pages/participant/participant?clubId=" + clubId,
		});
	},

	bindObjPickerChange(e) {
		console.log('picker发送选择改变，携带值为', e.detail.value);
		this.setData({
			arrIndex: e.detail.value,
		});
	},

	toCreateActivity(e) {
		var that = this
		var data = that.data
		console.log(data.managerClubs[data.arrIndex])
		my.navigateTo({
		  url: '../../pages/createactivity/createactivity?managerclubName=' 
		  		+ data.managerClubs[data.arrIndex].name,
		});
	}
});
